package com.zrrd.yunchmall.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yekong
 */
@SuppressWarnings("all")
@RestController
@RefreshScope//方法二：1.自动刷新属性的值
@RequestMapping("product")
public class ConfigTestController {
    //方法一：通过硬编码的方式，获取上下文环境中的属性最新值
    @Autowired
    private ConfigurableApplicationContext context;

    //方法二：2.获取author.name属性的值赋值给authorName
    @Value("${author.name}")
    private String authorName;

    @RequestMapping("/configTest")
    public String getAuthorProperty() {
        return context.getEnvironment().getProperty("author.name");
    }

    @RequestMapping("/configTest2")
    public String getAuthorProperty2() {
        return authorName;
    }
}
